package com.streetpower.controller;

import com.streetpower.common.result.Response;
import com.streetpower.facade.entity.User;
import com.streetpower.facade.service.LoginService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import static jdk.nashorn.internal.runtime.regexp.joni.Config.log;


/**
 * @Description: 登录接口
 * @Author: lipeng
 * @CreateDate: 2019/5/12 16:20
 */
@RestController
@Slf4j
public class LoginController {

    @Autowired
    private LoginService loginService;

    @GetMapping("/login")
    public Response login(String userName, String password){
        Response<User> response = new Response<>(true , 200);
        try{
            response = loginService.login(userName, password);
        }catch (Exception e){
            response.setCode(1000); //错误代码表
            response.setSuccess(false);
            response.setMessage("登录失败");
            response.setData(null);
            log.error("登录失败" ,e);
        }
        return response;
    }
}
